package com.ruoyi.voucher.service.impl;

import java.io.IOException;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.file.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.ruoyi.voucher.mapper.VoucherAccessoryMapper;
import com.ruoyi.voucher.domain.VoucherAccessory;
import com.ruoyi.voucher.service.IVoucherAccessoryService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 凭证附件Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@Service
public class VoucherAccessoryServiceImpl extends ServiceImpl<VoucherAccessoryMapper,VoucherAccessory> implements IVoucherAccessoryService
{
    @Autowired
    private VoucherAccessoryMapper voucherAccessoryMapper;

    @Value("${file.prefix}")
    public String localFilePrefix;
    @Value("${file.domain}")
    public String domain;
    @Value("${file.path}")
    private String localFilePath;
    /**
     * 查询凭证附件
     * 
     * @param id 凭证附件主键
     * @return 凭证附件
     */
    @Override
    public VoucherAccessory selectVoucherAccessoryById(Long id)
    {
        return voucherAccessoryMapper.selectVoucherAccessoryById(id);
    }

    /**
     * 查询凭证附件列表
     * 
     * @param voucherAccessory 凭证附件
     * @return 凭证附件
     */
    @Override
    public List<VoucherAccessory> selectVoucherAccessoryList(VoucherAccessory voucherAccessory)
    {
        return voucherAccessoryMapper.selectVoucherAccessoryList(voucherAccessory);
    }

    /**
     * 新增凭证附件
     * 
     * @param voucherAccessory 凭证附件
     * @return 结果
     */
    @Override
    public int insertVoucherAccessory(VoucherAccessory voucherAccessory)
    {
        return voucherAccessoryMapper.insertVoucherAccessory(voucherAccessory);
    }

    /**
     * 修改凭证附件
     * 
     * @param voucherAccessory 凭证附件
     * @return 结果
     */
    @Override
    public int updateVoucherAccessory(VoucherAccessory voucherAccessory)
    {
        return voucherAccessoryMapper.updateVoucherAccessory(voucherAccessory);
    }

    /**
     * 批量删除凭证附件
     * 
     * @param ids 需要删除的凭证附件主键
     * @return 结果
     */
    @Override
    public int deleteVoucherAccessoryByIds(Long[] ids)
    {
        return voucherAccessoryMapper.deleteVoucherAccessoryByIds(ids);
    }

    /**
     * 删除凭证附件信息
     * 
     * @param id 凭证附件主键
     * @return 结果
     */
    @Override
    public int deleteVoucherAccessoryById(Long id)
    {
        return voucherAccessoryMapper.deleteVoucherAccessoryById(id);
    }

    @Override
    public String uploadAccessory(MultipartFile file) throws IOException {
        String name = FileUploadUtils.upload(localFilePath, file);
        String url = domain + localFilePrefix + name;
//        VoucherAccessory voucherAccessory = new VoucherAccessory();
//        voucherAccessory.setName(name);
//        voucherAccessory.setAccessoryUrl(url);
        return url;
    }
}
